package com.noble.glamour.module.logic.socket;

import android.text.TextUtils;

import com.noble.library.host.Hosts;
import com.noble.library.log.PSP;

/**
 * socket长连接中一些常用的常量
 */
public class TCPConstant {
    private static final String TCP_HOST = "tcp_host";
    private static final String TCP_PORT = "tcp_port";

    public static void setTcpHost(String host) {
        PSP.getInstance().put(TCPConstant.TCP_HOST, host);
    }

    public static void setTcpPort(int portTcp) {
        PSP.getInstance().put(TCPConstant.TCP_PORT, portTcp);
    }

    //socket连接IP地址
    public static String getTcpHost() {
        String host = PSP.getInstance().getString(TCP_HOST, "");
        return TextUtils.isEmpty(host) ? Hosts.FATE_IT_TCP : host;
    }

    //socket连接端口
    public static int getTcpPort() {
        int port = PSP.getInstance().getInt(TCP_PORT, 0);
        return port <= 0 ? Hosts.FATE_IT_TCP_PORT : port;
    }

    /**
     * 即时通许中，CoreService连接服务器时，返回的几种状态。
     */
    public static final int SOCKET_STATUS_Login_Success = 0;    //登录成功
    public static final int SOCKET_STATUS_Login_Fail = 1;       //登录失败
    public static final int SOCKET_STATUS_Connected = 2;        //连接成功
    public static final int SOCKET_STATUS_Disconnect = 3;       //断开连接
    public static final int SOCKET_STATUS_ConnectIng = 4;       //正在连接

    /**
     * 维持长连接
     */
    public static long Heartbeat_Time = 60 * 1000;    //心跳时间间隔，60s
    public static final int SOCKET_CONNECT_TIMEOUT = 5000;             //Socket连接时超时时间
    public static final int SOCKET_AUTO_CONNECT_Increment_Time = 1000;  //Socket自动重连时间间隔

    // 系统消息  1000 - 1999
    public static final int MSG_HOST_RESET = 1000;           // 设置新的消息服务地址，返回Content:{"IpMsg":"", "PortTcp": 20001}
    public static final int MSG_ID_LOGIN_SUC = 1001;           // 注册登录成功：长连接从断开到连接状态，服务端回执消息
    public static final int MSG_ID_HEART_BEAT = 1002;          // 注册心跳：长连接维持期间，二次发送登录数据包的回复消息
    public static final int MSG_ID_LOGIN_FAIL = 1003;          // 注册登录失败
    public static final int MSG_ID_RE_LOGIN = 1004;            // 通知重新发送登录数据包： 进行socket重连后发送登录包
    public static final int MSG_ID_HEART_INTERVAL = 1005;      // 心跳间隔时间服务端通知，收到该消息，重置心跳间隔 Content:{"Heart": 11} 单位：s

    public static final int MSG_ID_UPDATE_AUTH = 1021;          // 更新Auth, 后台默默更新本地存储auth
    public static final int MSG_ID_OTHER_PLACE = 1022;          // 异地登陆踢下线
    public static final int MSG_ID_KICK_Offline = 1023;         // 强制下线
    public static final int MSG_ID_LOGIN_BLOCK = 1024;           // 账户封禁
}
